/**
 * Copyright (c) 2018-2025 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 * @author Adam Midlik <midlik@gmail.com>
 */

import { type ParamDefinition as PD } from '../param-definition';
import { capitalize } from '../string';
import { ColorList } from './color';

export const ColorLists = {
    // Brewer Color Lists
    // Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
    // Licensed under the Apache License, Version 2.0 (the "License");

    'reds': ColorList('Reds', 'sequential',
        'Reds, sequential color scheme from ColorBrewer 2.0',
        [0xfff5f0, 0xfee0d2, 0xfcbba1, 0xfc9272, 0xfb6a4a, 0xef3b2c, 0xcb181d, 0xa50f15, 0x67000d]
    ),
    'oranges': ColorList('Oranges', 'sequential',
        'Oranges, sequential color scheme from ColorBrewer 2.0',
        [0xfff5eb, 0xfee6ce, 0xfdd0a2, 0xfdae6b, 0xfd8d3c, 0xf16913, 0xd94801, 0xa63603, 0x7f2704]
    ),
    'greens': ColorList('Greens', 'sequential',
        'Greens, sequential color scheme from ColorBrewer 2.0',
        [0xf7fcf5, 0xe5f5e0, 0xc7e9c0, 0xa1d99b, 0x74c476, 0x41ab5d, 0x238b45, 0x006d2c, 0x00441b]
    ),
    'blues': ColorList('Blues', 'sequential',
        'Blues, sequential color scheme from ColorBrewer 2.0',
        [0xf7fbff, 0xdeebf7, 0xc6dbef, 0x9ecae1, 0x6baed6, 0x4292c6, 0x2171b5, 0x08519c, 0x08306b]
    ),
    'purples': ColorList('Purples', 'sequential',
        'Purples, sequential color scheme from ColorBrewer 2.0',
        [0xfcfbfd, 0xefedf5, 0xdadaeb, 0xbcbddc, 0x9e9ac8, 0x807dba, 0x6a51a3, 0x54278f, 0x3f007d]
    ),
    'greys': ColorList('Greys', 'sequential',
        'Greys, sequential color scheme from ColorBrewer 2.0',
        [0xffffff, 0xf0f0f0, 0xd9d9d9, 0xbdbdbd, 0x969696, 0x737373, 0x525252, 0x252525, 0x000000]
    ),
    'orange-red': ColorList('Orange-Red', 'sequential',
        'OrRd, sequential color scheme from ColorBrewer 2.0',
        [0xfff7ec, 0xfee8c8, 0xfdd49e, 0xfdbb84, 0xfc8d59, 0xef6548, 0xd7301f, 0xb30000, 0x7f0000]
    ),
    'blue-green': ColorList('Blue-Green', 'sequential',
        'BuGn, sequential color scheme from ColorBrewer 2.0',
        [0xf7fcfd, 0xe5f5f9, 0xccece6, 0x99d8c9, 0x66c2a4, 0x41ae76, 0x238b45, 0x006d2c, 0x00441b]
    ),
    'purple-blue-green': ColorList('Purple-Blue-Green', 'sequential',
        'PuBuGn, sequential color scheme from ColorBrewer 2.0',
        [0xfff7fb, 0xece2f0, 0xd0d1e6, 0xa6bddb, 0x67a9cf, 0x3690c0, 0x02818a, 0x016c59, 0x014636]
    ),
    'green-blue': ColorList('Green-Blue', 'sequential',
        'GnBu, sequential color scheme from ColorBrewer 2.0',
        [0xf7fcf0, 0xe0f3db, 0xccebc5, 0xa8ddb5, 0x7bccc4, 0x4eb3d3, 0x2b8cbe, 0x0868ac, 0x084081]
    ),
    'purple-blue': ColorList('Purple-Blue', 'sequential',
        'PuBu, sequential color scheme from ColorBrewer 2.0',
        [0xfff7fb, 0xece7f2, 0xd0d1e6, 0xa6bddb, 0x74a9cf, 0x3690c0, 0x0570b0, 0x045a8d, 0x023858]
    ),
    'blue-purple': ColorList('Blue-Purple', 'sequential',
        'BuPu, sequential color scheme from ColorBrewer 2.0',
        [0xf7fcfd, 0xe0ecf4, 0xbfd3e6, 0x9ebcda, 0x8c96c6, 0x8c6bb1, 0x88419d, 0x810f7c, 0x4d004b]
    ),
    'red-purple': ColorList('Red-Purple', 'sequential',
        'RdPu, sequential color scheme from ColorBrewer 2.0',
        [0xfff7f3, 0xfde0dd, 0xfcc5c0, 0xfa9fb5, 0xf768a1, 0xdd3497, 0xae017e, 0x7a0177, 0x49006a]
    ),
    'purple-red': ColorList('Purple-Red', 'sequential',
        'PuRd, sequential color scheme from ColorBrewer 2.0',
        [0xf7f4f9, 0xe7e1ef, 0xd4b9da, 0xc994c7, 0xdf65b0, 0xe7298a, 0xce1256, 0x980043, 0x67001f]
    ),
    'yellow-orange-red': ColorList('Yellow-Orange-Red', 'sequential',
        'YlOrRd, sequential color scheme from ColorBrewer 2.0',
        [0xffffcc, 0xffeda0, 0xfed976, 0xfeb24c, 0xfd8d3c, 0xfc4e2a, 0xe31a1c, 0xbd0026, 0x800026]
    ),
    'yellow-orange-brown': ColorList('Yellow-Orange-Brown', 'sequential',
        'YlOrBr, sequential color scheme from ColorBrewer 2.0',
        [0xffffe5, 0xfff7bc, 0xfee391, 0xfec44f, 0xfe9929, 0xec7014, 0xcc4c02, 0x993404, 0x662506]
    ),
    'yellow-green': ColorList('Yellow-Green', 'sequential',
        'YlGn, sequential color scheme from ColorBrewer 2.0',
        [0xffffe5, 0xf7fcb9, 0xd9f0a3, 0xaddd8e, 0x78c679, 0x41ab5d, 0x238443, 0x006837, 0x004529]
    ),
    'yellow-green-blue': ColorList('Yellow-Green-Blue', 'sequential',
        'YlGnBu, sequential color scheme from ColorBrewer 2.0',
        [0xffffd9, 0xedf8b1, 0xc7e9b4, 0x7fcdbb, 0x41b6c4, 0x1d91c0, 0x225ea8, 0x253494, 0x081d58]
    ),

    'red-blue': ColorList('Red-Blue', 'diverging',
        'RdBu, diverging color scheme from ColorBrewer 2.0',
        [0x67001f, 0xb2182b, 0xd6604d, 0xf4a582, 0xfddbc7, 0xf7f7f7, 0xd1e5f0, 0x92c5de, 0x4393c3, 0x2166ac, 0x053061]
    ),
    'red-grey': ColorList('Red-Grey', 'diverging',
        'RdGy, diverging color scheme from ColorBrewer 2.0',
        [0x67001f, 0xb2182b, 0xd6604d, 0xf4a582, 0xfddbc7, 0xffffff, 0xe0e0e0, 0xbababa, 0x878787, 0x4d4d4d, 0x1a1a1a]
    ),
    'pink-yellow-green': ColorList('Pink-Yellow-Green', 'diverging',
        'PiYG, diverging color scheme from ColorBrewer 2.0',
        [0x8e0152, 0xc51b7d, 0xde77ae, 0xf1b6da, 0xfde0ef, 0xf7f7f7, 0xe6f5d0, 0xb8e186, 0x7fbc41, 0x4d9221, 0x276419]
    ),
    'brown-white-green': ColorList('Brown-White-Green', 'diverging',
        'BrBG, diverging color scheme from ColorBrewer 2.0',
        [0x543005, 0x8c510a, 0xbf812d, 0xdfc27d, 0xf6e8c3, 0xf5f5f5, 0xc7eae5, 0x80cdc1, 0x35978f, 0x01665e, 0x003c30]
    ),
    'purple-green': ColorList('Purple-Green', 'diverging',
        'PRGn, diverging color scheme from ColorBrewer 2.0',
        [0x40004b, 0x762a83, 0x9970ab, 0xc2a5cf, 0xe7d4e8, 0xf7f7f7, 0xd9f0d3, 0xa6dba0, 0x5aae61, 0x1b7837, 0x00441b]
    ),
    // Including both purple-orange and orange-purple here because ColorBrew is a bit messy (calls it PuOr but the order is orange->purple), D3.js has PuOr in the correct order
    'purple-orange': ColorList('Purple-Orange', 'diverging',
        'PuOr, diverging color scheme from ColorBrewer 2.0',
        [0x2d004b, 0x542788, 0x8073ac, 0xb2abd2, 0xd8daeb, 0xf7f7f7, 0xfee0b6, 0xfdb863, 0xe08214, 0xb35806, 0x7f3b08]
    ),
    'orange-purple': ColorList('Orange-Purple', 'diverging',
        'Reversed PuOr, diverging color scheme from ColorBrewer 2.0',
        [0x7f3b08, 0xb35806, 0xe08214, 0xfdb863, 0xfee0b6, 0xf7f7f7, 0xd8daeb, 0xb2abd2, 0x8073ac, 0x542788, 0x2d004b]
    ),
    'red-yellow-green': ColorList('Red-Yellow-Green', 'diverging',
        'RdYlGn, diverging color scheme from ColorBrewer 2.0',
        [0xa50026, 0xd73027, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xd9ef8b, 0xa6d96a, 0x66bd63, 0x1a9850, 0x006837]
    ),
    'red-yellow-blue': ColorList('Red-Yellow-Blue', 'diverging',
        'RdYlBu, diverging color scheme from ColorBrewer 2.0',
        [0xa50026, 0xd73027, 0xf46d43, 0xfdae61, 0xfee090, 0xffffbf, 0xe0f3f8, 0xabd9e9, 0x74add1, 0x4575b4, 0x313695]
    ),
    'spectral': ColorList('Spectral', 'diverging',
        'Spectral, diverging color scheme from ColorBrewer 2.0',
        [0x9e0142, 0xd53e4f, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xe6f598, 0xabdda4, 0x66c2a5, 0x3288bd, 0x5e4fa2]
    ),

    // Matplotlib colormaps, including various perceptually uniform shades, see https://bids.github.io/colormap/

    'magma': ColorList('Magma', 'sequential',
        'Magma, sequential color scheme from Matplotlib, perceptually uniform shades of black-red-white',
        [0x000004, 0x02020b, 0x050416, 0x090720, 0x0e0b2b, 0x140e36, 0x1a1042, 0x21114d, 0x29115a, 0x331067, 0x3b0f70, 0x440f76, 0x4c117a, 0x54137d, 0x5b157f, 0x641a80, 0x6b1d81, 0x752181, 0x7c2382, 0x842681, 0x8c2981, 0x942c80, 0x9c2e7f, 0xa5317e, 0xad347c, 0xb73779, 0xbf3a77, 0xc73d73, 0xce3f70, 0xd6456b, 0xde4968, 0xe44f64, 0xea5661, 0xef5d5e, 0xf4675c, 0xf7705c, 0xf9795d, 0xfb835f, 0xfc8c63, 0xfd9668, 0xfe9f6d, 0xfea973, 0xfeb47b, 0xfebd82, 0xfec68a, 0xfecf92, 0xfed89a, 0xfde2a3, 0xfdebac, 0xfcf4b6, 0xfcfdbf]
    ),
    'magma-no-black': ColorList('Magma (no black)', 'sequential', // used to be called 'magma'
        'Magma, sequential color scheme from Matplotlib, perceptually uniform shades of black-red-white (with the black region removed)',
        [0x420f74, 0x4a1079, 0x52127c, 0x5a157e, 0x61187f, 0x691c80, 0x711f81, 0x792281, 0x812581, 0x892881, 0x912a80, 0x992d7f, 0xa12f7e, 0xa9327c, 0xb1357a, 0xb93778, 0xc23a75, 0xca3e72, 0xd1426e, 0xd9466a, 0xe04b66, 0xe65162, 0xec585f, 0xf0605d, 0xf4685b, 0xf7715b, 0xf97b5d, 0xfb8460, 0xfc8e63, 0xfd9768, 0xfda16e, 0xfeaa74, 0xfeb37b, 0xfebc82, 0xfec689, 0xfdcf92, 0xfdd89a, 0xfde1a3, 0xfceaac, 0xfcf3b5, 0xfbfcbf]
    ),
    'inferno': ColorList('Inferno', 'sequential',
        'Inferno, sequential color scheme from Matplotlib, perceptually uniform shades of black-red-yellow',
        [0x000004, 0x02020c, 0x050417, 0x0a0722, 0x10092d, 0x160b39, 0x1e0c45, 0x250c51, 0x2f0a5b, 0x390963, 0x420a68, 0x4a0c6b, 0x520e6d, 0x5a116e, 0x62136e, 0x6a176e, 0x721a6e, 0x7c1d6d, 0x84206b, 0x8c2369, 0x932667, 0x9b2964, 0xa32c61, 0xab2f5e, 0xb3325a, 0xbc3754, 0xc33b4f, 0xca404a, 0xcf4445, 0xd74b3e, 0xdd513a, 0xe25734, 0xe75e2e, 0xeb6628, 0xf06f20, 0xf37819, 0xf68013, 0xf8890c, 0xfa9207, 0xfb9b06, 0xfca50a, 0xfcae12, 0xfbba1f, 0xfac42a, 0xf8cd37, 0xf6d746, 0xf4e156, 0xf2ea69, 0xf2f27d, 0xf5f992, 0xfcffa4]
    ),
    'inferno-no-black': ColorList('Inferno (no black)', 'sequential', // used to be called 'inferno'
        'Inferno, sequential color scheme from Matplotlib, perceptually uniform shades of black-red-yellow (with the black region removed)',
        [0x480b6a, 0x500d6c, 0x58106d, 0x60136e, 0x68166e, 0x70196e, 0x781c6d, 0x801f6b, 0x88216a, 0x902468, 0x982765, 0xa02a62, 0xa72d5f, 0xaf315b, 0xb73456, 0xbe3852, 0xc53d4d, 0xcc4148, 0xd24742, 0xd94d3d, 0xde5337, 0xe45a31, 0xe8612b, 0xed6825, 0xf0701e, 0xf37918, 0xf68111, 0xf88a0b, 0xfa9306, 0xfb9d06, 0xfba60b, 0xfbb014, 0xfbb91e, 0xf9c32a, 0xf8cd37, 0xf5d745, 0xf3e056, 0xf1e968, 0xf1f27d, 0xf5f891, 0xfcfea4],
    ),
    'plasma': ColorList('Plasma', 'sequential',
        'Plasma, sequential color scheme from Matplotlib, perceptually uniform shades of blue-red-yellow',
        [0x1b068c, 0x250591, 0x2f0495, 0x380499, 0x40039c, 0x49029f, 0x5101a2, 0x5901a4, 0x6100a6, 0x6800a7, 0x7000a8, 0x7801a8, 0x7f03a7, 0x8607a6, 0x8e0ca4, 0x9511a1, 0x9b179e, 0xa21c9a, 0xa82296, 0xae2791, 0xb42d8d, 0xb93388, 0xbe3883, 0xc33e7f, 0xc8447a, 0xcd4975, 0xd14f71, 0xd6556d, 0xda5a68, 0xde6064, 0xe26660, 0xe56c5b, 0xe97257, 0xec7853, 0xef7e4e, 0xf2854a, 0xf58b46, 0xf79241, 0xf9993d, 0xfaa039, 0xfca735, 0xfdaf31, 0xfdb62d, 0xfdbe29, 0xfdc626, 0xfcce25, 0xfad624, 0xf8df24, 0xf5e726, 0xf2f026, 0xeff821]
    ),
    'viridis': ColorList('Viridis', 'sequential',
        'Viridis, sequential color scheme from Matplotlib, perceptually uniform shades of blue-green-yellow',
        [0x45085b, 0x470f62, 0x471669, 0x481d6f, 0x482374, 0x472a79, 0x46307d, 0x453681, 0x433c84, 0x414286, 0x3e4888, 0x3c4d8a, 0x3a538b, 0x37588c, 0x355d8c, 0x32628d, 0x30678d, 0x2e6c8e, 0x2c718e, 0x2a768e, 0x287a8e, 0x267f8e, 0x24848d, 0x23898d, 0x218d8c, 0x1f928c, 0x1e978a, 0x1e9b89, 0x1ea087, 0x20a585, 0x23a982, 0x28ae7f, 0x2eb27c, 0x35b778, 0x3dbb74, 0x45bf6f, 0x4fc369, 0x59c764, 0x64cb5d, 0x70ce56, 0x7cd24f, 0x88d547, 0x95d73f, 0xa2da37, 0xafdc2e, 0xbdde26, 0xcae01e, 0xd7e219, 0xe4e318, 0xf1e51c, 0xfde724]
    ),
    'cividis': ColorList('Cividis', 'sequential',
        'Cividis, sequential color scheme from Matplotlib, perceptually uniform shades of blue-grey-yellow, should look effectively identical to colorblind and non-colorblind users',
        [0x002051, 0x002459, 0x00275f, 0x012b64, 0x052e68, 0x0a326a, 0x10366c, 0x15396d, 0x1d3d6e, 0x24406e, 0x2b446e, 0x32486e, 0x394b6e, 0x404f6e, 0x45526d, 0x4d566d, 0x535a6e, 0x595e6e, 0x5e616e, 0x64656f, 0x696970, 0x6e6c71, 0x727072, 0x777473, 0x7b7874, 0x7f7c75, 0x837f76, 0x888377, 0x8c8677, 0x908b78, 0x948f78, 0x999378, 0x9d9778, 0xa29b78, 0xa7a077, 0xada476, 0xb2a874, 0xb8ac72, 0xbeb170, 0xc4b56d, 0xcaba6a, 0xd1be66, 0xd7c363, 0xdec85f, 0xe4cc5a, 0xead156, 0xefd652, 0xf4db4e, 0xf8e04b, 0xfbe548, 0xfdea45]
    ),
    'twilight': ColorList('Twilight', 'cyclical',
        'Twilight, cyclical color scheme from Matplotlib, perceptually uniform shades of white-blue-black-red-white',
        [0xdfd9e1, 0xd8d7dd, 0xced3d8, 0xc2cdd3, 0xb4c7ce, 0xa7c0ca, 0x9ab8c7, 0x8eb0c5, 0x83a8c3, 0x7a9fc2, 0x7297c0, 0x6b8ebf, 0x6684bd, 0x637bbb, 0x6171b9, 0x5f67b6, 0x5e5cb2, 0x5e51ad, 0x5d46a7, 0x5c3c9f, 0x5b3196, 0x58278b, 0x531e7d, 0x4d176e, 0x46135f, 0x3e1151, 0x381045, 0x32113b, 0x301336, 0x361138, 0x3e113c, 0x471240, 0x521445, 0x5e1749, 0x6a1a4d, 0x761e4f, 0x812350, 0x8b2a50, 0x95324f, 0x9d3a4f, 0xa5434f, 0xac4d50, 0xb25752, 0xb86155, 0xbc6c59, 0xc0775f, 0xc48267, 0xc78d70, 0xc9987b, 0xcca389, 0xceae97, 0xd2b8a6, 0xd6c1b5, 0xdacac4, 0xddd1d1, 0xe0d6db, 0xe1d8e1]
    ),

    // Qualitative schemes from ColorBrewer (putting them here so that order in UI is sequential, diverging, cyclical, categorical)

    'set-2': ColorList('Set-2', 'qualitative',
        'Set2, categorical color scheme from ColorBrewer 2.0',
        [0x66c2a5, 0xfc8d62, 0x8da0cb, 0xe78ac3, 0xa6d854, 0xffd92f, 0xe5c494, 0xb3b3b3]
    ),
    'accent': ColorList('Accent', 'qualitative',
        'Accent, categorical color scheme from ColorBrewer 2.0',
        [0x7fc97f, 0xbeaed4, 0xfdc086, 0xffff99, 0x386cb0, 0xf0027f, 0xbf5b17, 0x666666]
    ),
    'set-1': ColorList('Set-1', 'qualitative',
        'Set1, categorical color scheme from ColorBrewer 2.0',
        [0xe41a1c, 0x377eb8, 0x4daf4a, 0x984ea3, 0xff7f00, 0xffff33, 0xa65628, 0xf781bf, 0x999999]
    ),
    'set-3': ColorList('Set-3', 'qualitative',
        'Set3, categorical color scheme from ColorBrewer 2.0',
        [0x8dd3c7, 0xffffb3, 0xbebada, 0xfb8072, 0x80b1d3, 0xfdb462, 0xb3de69, 0xfccde5, 0xd9d9d9, 0xbc80bd, 0xccebc5, 0xffed6f]
    ),
    'dark-2': ColorList('Dark-2', 'qualitative',
        'Dark2, categorical color scheme from ColorBrewer 2.0',
        [0x1b9e77, 0xd95f02, 0x7570b3, 0xe7298a, 0x66a61e, 0xe6ab02, 0xa6761d, 0x666666]
    ),
    'paired': ColorList('Paired', 'qualitative',
        'Paired, categorical color scheme from ColorBrewer 2.0',
        [0xa6cee3, 0x1f78b4, 0xb2df8a, 0x33a02c, 0xfb9a99, 0xe31a1c, 0xfdbf6f, 0xff7f00, 0xcab2d6, 0x6a3d9a, 0xffff99, 0xb15928]
    ),
    'pastel-2': ColorList('Pastel-2', 'qualitative',
        'Pastel2, categorical color scheme from ColorBrewer 2.0',
        [0xb3e2cd, 0xfdcdac, 0xcbd5e8, 0xf4cae4, 0xe6f5c9, 0xfff2ae, 0xf1e2cc, 0xcccccc]
    ),
    'pastel-1': ColorList('Pastel-1', 'qualitative',
        'Pastel1, categorical color scheme from ColorBrewer 2.0',
        [0xfbb4ae, 0xb3cde3, 0xccebc5, 0xdecbe4, 0xfed9a6, 0xffffcc, 0xe5d8bd, 0xfddaec, 0xf2f2f2]
    ),

    // https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html

    'turbo': ColorList('Turbo', 'sequential',
        'Turbo color scheme from D3.js, improved (smooth) rainbow colormap for visualization',
        [0x23171b, 0x362356, 0x422f85, 0x493caa, 0x4b4ac7, 0x4a58dd, 0x4666eb, 0x4174f4, 0x3b82f8, 0x3590f8, 0x2f9df5, 0x2aaaef, 0x27b6e6, 0x25c2dc, 0x25ccd0, 0x27d7c4, 0x2be0b7, 0x31e8aa, 0x38ee9d, 0x42f490, 0x4df884, 0x59fb78, 0x67fd6d, 0x76fe63, 0x85fd59, 0x95fb51, 0xa4f749, 0xb4f242, 0xc2ec3c, 0xd1e436, 0xdedd32, 0xead32e, 0xf4c92b, 0xfcbd28, 0xffb125, 0xffa423, 0xff9721, 0xff891e, 0xff7b1c, 0xfd6d1a, 0xf65f18, 0xec5115, 0xe14412, 0xd5370f, 0xc72c0c, 0xba2208, 0xad1905, 0xa21202, 0x980e00, 0x920c00, 0x900c00]
    ),
    'turbo-no-black': ColorList('Turbo (no black)', 'sequential', // used to be called 'turbo'
        'Turbo color scheme from D3.js, improved (smooth) rainbow colormap for visualization, with black region removed',
        [0x4a41b5, 0x4a58dd, 0x426ff2, 0x3987f9, 0x2f9df5, 0x28b2e9, 0x25c6d8, 0x27d7c4, 0x2ee5ae, 0x3bf098, 0x4df884, 0x62fd70, 0x7bfe5f, 0x95fb51, 0xaff444, 0xc8ea3a, 0xdedd32, 0xf0cc2c, 0xfeb927, 0xffa423, 0xff8e1f, 0xff761c, 0xf65f18, 0xe54813, 0xd0330e, 0xba2208, 0xa51403, 0x960d00]
    ),

    // Other colormaps from D3.js (https://observablehq.com/@d3/color-schemes)

    'warm': ColorList('Warm', 'sequential',
        'Warm, sequential color scheme from D3.js',
        [0x6e40aa, 0x753fad, 0x7d3faf, 0x863eb1, 0x8e3eb2, 0x963db3, 0x9e3db3, 0xa73cb3, 0xaf3cb2, 0xb73cb1, 0xbf3caf, 0xc73dac, 0xcf3da9, 0xd63ea6, 0xdc3fa2, 0xe4419d, 0xea4299, 0xf04494, 0xf5468e, 0xfa4988, 0xfe4b83, 0xff4e7c, 0xff5276, 0xff5670, 0xff5a6a, 0xff5e63, 0xff635d, 0xff6757, 0xff6c51, 0xff724b, 0xff7847, 0xff7d42, 0xff833d, 0xff8a39, 0xff9036, 0xfb9633, 0xf69d31, 0xf2a42f, 0xedaa2e, 0xe7b12e, 0xe2b72f, 0xdcbe30, 0xd7c432, 0xd1ca34, 0xccd038, 0xc6d63c, 0xc1dc41, 0xbce146, 0xb7e64c, 0xb3eb53, 0xaff05b]
    ),
    'cool': ColorList('Cool', 'sequential',
        'Cool, sequential color scheme from D3.js',
        [0x6e40aa, 0x6c43b1, 0x6947b7, 0x674bbd, 0x6450c3, 0x6054c8, 0x5d59cd, 0x595ed1, 0x5563d5, 0x5169d9, 0x4c6edb, 0x4874de, 0x437ae0, 0x3f80e1, 0x3a85e1, 0x368ce1, 0x3292e1, 0x2e98df, 0x2a9fde, 0x27a5db, 0x23abd8, 0x21b1d5, 0x1eb7d1, 0x1cbccc, 0x1bc2c7, 0x1ac7c2, 0x19cdbc, 0x19d1b6, 0x1ad5b0, 0x1bdbaa, 0x1ddfa3, 0x20e29c, 0x23e696, 0x27e98f, 0x2bec89, 0x30ef82, 0x36f17c, 0x3cf276, 0x43f471, 0x4af56c, 0x52f667, 0x5af663, 0x63f75f, 0x6cf65c, 0x75f65a, 0x7ff658, 0x88f557, 0x92f457, 0x9cf357, 0xa6f159, 0xaff05b]
    ),
    'cubehelix-default': ColorList('CubehelixDefault', 'sequential',
        'CubehelixDefault, sequential color scheme from D3.js',
        [0x000000, 0x080308, 0x0f0612, 0x140a1c, 0x180f26, 0x1a1530, 0x1b1c39, 0x1a2241, 0x192b47, 0x17344b, 0x163d4e, 0x15464e, 0x154f4d, 0x17574a, 0x195e46, 0x1f6642, 0x266c3c, 0x2f7137, 0x397533, 0x467830, 0x54792f, 0x637a2f, 0x737b32, 0x827a37, 0x927a3f, 0xa07949, 0xad7955, 0xb97963, 0xc27a71, 0xca7c82, 0xd07e93, 0xd382a3, 0xd487b3, 0xd48dc1, 0xd294ce, 0xcf9cda, 0xcca5e3, 0xc9aeea, 0xc5b8ef, 0xc3c1f2, 0xc1caf3, 0xc2d3f3, 0xc3dbf2, 0xc7e2f1, 0xcce8f0, 0xd2eeef, 0xdaf2ef, 0xe3f6f0, 0xecf9f3, 0xf6fcf8, 0xffffff]
    ),
    'rainbow': ColorList('Rainbow', 'cyclical',
        'Rainbow, cyclical color scheme from D3.js',
        [0x6e40aa, 0x7d3faf, 0x8e3eb2, 0x9e3db3, 0xaf3cb2, 0xbf3caf, 0xcf3da9, 0xdc3fa2, 0xea4299, 0xf5468e, 0xfe4b83, 0xff5276, 0xff5a6a, 0xff635d, 0xff6c51, 0xff7847, 0xff833d, 0xff9036, 0xf69d31, 0xedaa2e, 0xe2b72f, 0xd7c432, 0xccd038, 0xc1dc41, 0xb7e64c, 0xaff05b, 0x9cf357, 0x88f557, 0x75f659, 0x62f75f, 0x52f667, 0x43f471, 0x36f17c, 0x2bec89, 0x23e696, 0x1ddfa3, 0x1ad6b0, 0x19cdbc, 0x1bc2c7, 0x1eb7d1, 0x23abd8, 0x2a9fde, 0x3292e1, 0x3a86e1, 0x437ae0, 0x4c6edb, 0x5563d5, 0x5d59cd, 0x6450c3, 0x6947b7, 0x6e40aa]
    ),
    'sinebow': ColorList('Sinebow', 'cyclical',
        'Sinebow, cyclical color scheme from D3.js',
        [0xff4040, 0xfe4e32, 0xfb5d26, 0xf66d1c, 0xef7d12, 0xe78d0b, 0xdc9d05, 0xd1ab02, 0xc4bb00, 0xb6c800, 0xa7d503, 0x97e007, 0x88ea0d, 0x77f215, 0x68f81e, 0x58fc2a, 0x49ff37, 0x3bff44, 0x2efd53, 0x23fa62, 0x18f472, 0x10ed82, 0x09e392, 0x04d9a2, 0x01cdb1, 0x00bfbf, 0x01b1cd, 0x04a2d9, 0x0892e2, 0x1081ed, 0x1872f4, 0x2362fa, 0x2e53fd, 0x3b44ff, 0x4937ff, 0x582afc, 0x681ff8, 0x7715f2, 0x880dea, 0x9707e0, 0xa703d5, 0xb600c8, 0xc400bb, 0xd102ac, 0xdc059d, 0xe70b8d, 0xef127d, 0xf61c6d, 0xfb265d, 0xfe324e, 0xff4040]
    ),
    'category-10': ColorList('Category10', 'qualitative',
        'Category10, categorical color scheme from D3.js / tab10 from Matplotlib (default in Matplotlib)',
        [0x1f77b4, 0xff7f0e, 0x2ca02c, 0xd62728, 0x9467bd, 0x8c564b, 0xe377c2, 0x7f7f7f, 0xbcbd22, 0x17becf]
    ),
    'observable-10': ColorList('Observable10', 'qualitative',
        'Observable10, categorical color scheme from D3.js',
        [0x4269d0, 0xefb118, 0xff725c, 0x6cc5b0, 0x3ca951, 0xff8ab7, 0xa463f2, 0x97bbf5, 0x9c6b4e, 0x9498a0]
    ),
    'tableau-10': ColorList('Tableau10', 'qualitative',
        'Tableau10, categorical color scheme from D3.js',
        [0x4e79a7, 0xf28e2c, 0xe15759, 0x76b7b2, 0x59a14f, 0xedc949, 0xaf7aa1, 0xff9da7, 0x9c755f, 0xbab0ab]
    ),

    // Other

    'simple-rainbow': ColorList('Simple rainbow', 'sequential', // used to be called 'rainbow'
        'Simple 5-color rainbow (blue-green-yellow-orange-red)',
        [0x3361E1, 0x35A845, 0xF9FF00, 0xEC8711, 0xBF2222]
    ),
    'red-white-blue': ColorList('Red-White-Blue', 'diverging',
        'Diverging color scheme with red-white-blue',
        [0xBF2222, 0xFFFFFF, 0x3361E1]
    ),
    'many-distinct': ColorList('Many-Distinct', 'qualitative',
        'Customized color scheme combining colors from multiple standard schemes (Dark2, Set1, Set2)',
        [
            // dark-2
            0x1b9e77, 0xd95f02, 0x7570b3, 0xe7298a, 0x66a61e, 0xe6ab02, 0xa6761d, 0x666666,
            // set-1
            0xe41a1c, 0x377eb8, 0x4daf4a, 0x984ea3, 0xff7f00, 0xffff33, 0xa65628, 0xf781bf, 0x999999,
            // set-2
            0x66c2a5, 0xfc8d62, 0x8da0cb, 0xe78ac3, 0xa6d854, 0xffd92f, 0xe5c494, 0xb3b3b3
        ]
    ),
};

export type ColorListName = keyof typeof ColorLists
export const ColorListNames = Object.keys(ColorLists) as ColorListName[];
export const ColorListOptions: PD.SelectOption<ColorListName>[] = ColorListNames.map(name => [name, ColorLists[name].label, capitalize(ColorLists[name].type), ColorLists[name].description]);

export const ColorListOptionsScale: PD.SelectOption<ColorListName>[] = ColorListOptions.filter(v => ColorLists[v[0]].type === 'sequential' || ColorLists[v[0]].type === 'diverging' || ColorLists[v[0]].type === 'cyclical');
export const ColorListOptionsSet: PD.SelectOption<ColorListName>[] = ColorListOptions.filter(v => ColorLists[v[0]].type === 'qualitative');

export function getColorListFromName(name: ColorListName) {
    if (name in ColorLists) return ColorLists[name as ColorListName];
    console.warn(`unknown color list named '${name}'`);
    return ColorLists['red-yellow-blue'];
}
